package demo;

import java.util.ArrayList;
import java.util.Collection;

//Day07
public class Day16004 {
    public static void main(String[] args) {
        Collection<Double> collection=new ArrayList<>();
        collection.add(88.5);
        collection.add(39.2);
        collection.add(77.1);
        collection.add(56.8);
        collection.add(89.0);
        collection.add(99.0);
        collection.add(59.5);

//        打印所有
        all(collection);
//        打印不及格
        fail(collection);
//        计算不及格数量和平均分
        avg(collection);
//        求最高分
        max(collection);
    }

    private static void max(Collection<Double> collection) {
        System.out.println("最高分为：");
        Double maxScore=0.00;
        for (Double d:
                collection) {
            if(maxScore<d)
                maxScore=d;
        }
        System.out.println(maxScore);
    }
    private static void avg(Collection<Double> collection) {
        System.out.println("\n打印不及格成绩份数和平均分：");
        Double add=0.00;
        Integer count=0;
        for (Double d:
             collection) {
            if(d<60){
                count++;
                add+=d;
            }
        }
        System.out.println("不及格份数："+count);
        System.out.println("不及格平均分："+add/count);
    }

    private static void fail(Collection<Double> collection) {
        System.out.println("\n打印不及格成绩：");
        for (Double d:
             collection) {
            if(d<60)
                System.out.print(d+" ");
        }
    }

    private static void all(Collection<Double> collection) {
        System.out.println("打印所有成绩：");
        for (Double d:
             collection) {
            System.out.print(d+" ");
        }
    }
}
